# Contributor: Anjandev Momi <anjan@momi.ca>
# Maintainer: Anjandev Momi <anjan@momi.ca>
pkgname=jami-daemon
pkgver=4.0.0_git20230925
pkgrel=1
_gitrev=f19b0fad9b99181e9a5e5a892ae354d940db2bb2
_pjprojectver=1489db073be280629e41d387c1c2561f20b0bfb3
_dhtnetver=4796de15ed32b41949489c328bc250d17c431c80
pkgdesc="Free and universal communication platform which preserves the users’ privacy and freedoms (daemon component)"
url="https://jami.net"
arch="all !ppc64le !s390x !riscv64" # no webrtc-audio-processing
license="GPL-3.0-or-later"
makedepends="
	alsa-lib-dev
	asio-dev
	cmake
	eudev-dev
	fmt-dev
	ffmpeg-dev
	gnutls-dev
	jsoncpp-dev
	libarchive-dev
	libgit2-dev
	libsecp256k1-dev
	libupnp-dev
	meson
	msgpack-cxx-dev
	opendht-dev
	pulseaudio-dev
	restinio-dev
	speex-dev
	speexdsp-dev
	sqlite-dev
	webrtc-audio-processing-dev
	yaml-cpp-dev
	zlib-dev
	"
subpackages="$pkgname-dev"
source="$pkgname-$_gitrev.tar.gz::https://git.jami.net/savoirfairelinux/jami-daemon/-/archive/$_gitrev/jami-daemon-$_gitrev.tar.gz
	pjproject-$_pjprojectver.tar.gz.noauto::https://github.com/savoirfairelinux/pjproject/archive/$_pjprojectver/pjproject-$_pjprojectver.tar.gz
	dhtnet-$_dhtnetver.tar.gz.noauto::https://git.jami.net/savoirfairelinux/dhtnet/-/archive/$_dhtnetver/dhtnet-$_dhtnetver.tar.gz
	dhtnet-unpack-dir.patch
	"
builddir="$srcdir/$pkgname-$_gitrev"
options="!check" # https://git.jami.net/savoirfairelinux/jami-daemon/-/issues/649

prepare() {
	default_prepare

	cp -v ../pjproject-$_pjprojectver.tar.gz.noauto \
		contrib/tarballs/pjproject-$_pjprojectver.tar.gz
	cp -v ../dhtnet-$_dhtnetver.tar.gz.noauto \
		contrib/tarballs/dhtnet-$_dhtnetver.tar.gz
	mkdir -v contrib/native
}

build() {
	cd contrib/native
	../bootstrap \
		--disable-downloads \
		--disable-all \
		--enable-pjproject \
		--enable-dhtnet
	make DEPS_pjproject= DEPS_dhtnet=pjproject

	cd "$builddir"
	abuild-meson \
		-Dinterfaces=library \
		-Dopensl=disabled \
		-Dportaudio=disabled \
		-Dtests=false \
		-Dpkg_config_path="$builddir/contrib/$(cc -dumpmachine)/lib/pkgconfig" \
		. output
	meson compile -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

sha512sums="
0d8591013d1e26c436de593d1ee974bf334acdb70ac2e7e2fab3d1e426bb52b7a2b3c8de21603c5945dd2f7829caf781982c95dcc5efa7fe225aa6ba49f64fbb  jami-daemon-f19b0fad9b99181e9a5e5a892ae354d940db2bb2.tar.gz
4a7cf995827f3d450627f32dbba463593e7ee9e268e6050c12622cae9c5ee8b6f7aadd1897e218b5665f467d89d40608681e56017d3cf817b69ad7348070afc7  pjproject-1489db073be280629e41d387c1c2561f20b0bfb3.tar.gz.noauto
c940ea273c25a38ca1d2b63077dddfeed7740405d5c16ac8f8db0a14e3fdf838a69f4c09bd68ef98b72fe04d1a3feb3f61fed2d34fb8e073c492211c121b8fae  dhtnet-4796de15ed32b41949489c328bc250d17c431c80.tar.gz.noauto
812b720831d35fffbaef1bb64cdc085bc72fb0f92f6e8ebe06ff3f1a20cf5a07cdd9dbc6dd00694cc880e7f905dfdc0fa956127b4bcb3ee78c4e08b763d2d807  dhtnet-unpack-dir.patch
"
